package com.ibeeking.gateway.open.constant;

import com.ibeeking.nematos.constants.enums.LogConstant;
import com.ibeeking.nematos.utils.data.StringUtils;
import org.apache.logging.log4j.ThreadContext;

import java.util.UUID;

/**
 * @ClassName ThreadContextCache
 * @Description
 * @Author ibeeking
 * @Date 2020-12-24 15:00
 **/
public class ThreadContextCache {
    /**
     * 本地线程存储
     */
    public static void threadContext(String tenantId,String traceId,String loginSystem,String loginRole,String userId, String userName, String demoUser, String industry) {
        //请求链路追踪id
        ThreadContext.put(LogConstant.TRACE_ID, StringUtils.isBlank(traceId) ? UUID.randomUUID().toString().replaceAll("-", "") : traceId);
        //操作人
        ThreadContext.put(LogConstant.TENANT_ID, tenantId);
        ThreadContext.put(LogConstant.USER_ID, userId);
        ThreadContext.put(LogConstant.USER_NAME, userName);
        ThreadContext.put(LogConstant.LOGIN_SYSTEM, loginSystem);

        ThreadContext.put(LogConstant.LOGIN_ROLE, loginRole);
        ThreadContext.put(LogConstant.AM_DEMO_USER, demoUser);
        ThreadContext.put(LogConstant.INDUSTRY, industry);
    }
}
